<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActionController::RequestProfiler</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActionController::RequestProfiler</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/request_profiler_rb.html">
                vendor/rails/actionpack/lib/action_controller/request_profiler.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000383">benchmark</a>&nbsp;&nbsp;
      <a href="#M000385">default_options</a>&nbsp;&nbsp;
      <a href="#M000387">load_ruby_prof</a>&nbsp;&nbsp;
      <a href="#M000379">new</a>&nbsp;&nbsp;
      <a href="#M000386">parse_options</a>&nbsp;&nbsp;
      <a href="#M000382">profile</a>&nbsp;&nbsp;
      <a href="#M000381">run</a>&nbsp;&nbsp;
      <a href="#M000380">run</a>&nbsp;&nbsp;
      <a href="#M000388">show_profile_results</a>&nbsp;&nbsp;
      <a href="#M000384">warmup</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Class <a href="RequestProfiler/Sandbox.html" class="link">ActionController::RequestProfiler::Sandbox</a><br />

    </div>




    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">options</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000379" class="method-detail">
        <a name="M000379"></a>

        <div class="method-heading">
          <a href="#M000379" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000379-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000379-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 49</span>
49:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
50:       <span class="ruby-ivar">@options</span> = <span class="ruby-identifier">default_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
51:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000380" class="method-detail">
        <a name="M000380"></a>

        <div class="method-heading">
          <a href="#M000380" class="method-signature">
          <span class="method-name">run</span><span class="method-args">(args = nil, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000380-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000380-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 54</span>
54:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">run</span>(<span class="ruby-identifier">args</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">options</span> = {})
55:       <span class="ruby-identifier">profiler</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>)
56:       <span class="ruby-identifier">profiler</span>.<span class="ruby-identifier">parse_options</span>(<span class="ruby-identifier">args</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>
57:       <span class="ruby-identifier">profiler</span>.<span class="ruby-identifier">run</span>
58:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000383" class="method-detail">
        <a name="M000383"></a>

        <div class="method-heading">
          <a href="#M000383" class="method-signature">
          <span class="method-name">benchmark</span><span class="method-args">(sandbox)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000383-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000383-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 81</span>
81:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">benchmark</span>(<span class="ruby-identifier">sandbox</span>)
82:       <span class="ruby-identifier">sandbox</span>.<span class="ruby-identifier">request_count</span> = <span class="ruby-value">0</span>
83:       <span class="ruby-identifier">elapsed</span> = <span class="ruby-identifier">sandbox</span>.<span class="ruby-identifier">benchmark</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:n</span>]).<span class="ruby-identifier">to_f</span>
84:       <span class="ruby-identifier">count</span> = <span class="ruby-identifier">sandbox</span>.<span class="ruby-identifier">request_count</span>.<span class="ruby-identifier">to_i</span>
85:       <span class="ruby-identifier">puts</span> <span class="ruby-value str">'%.2f sec, %d requests, %d req/sec'</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">elapsed</span>, <span class="ruby-identifier">count</span>, <span class="ruby-identifier">count</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">elapsed</span>]
86:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000385" class="method-detail">
        <a name="M000385"></a>

        <div class="method-heading">
          <a href="#M000385" class="method-signature">
          <span class="method-name">default_options</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000385-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000385-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 92</span>
92:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default_options</span>
93:       { <span class="ruby-identifier">:n</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">100</span>, <span class="ruby-identifier">:open</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'open %s &amp;'</span> }
94:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000386" class="method-detail">
        <a name="M000386"></a>

        <div class="method-heading">
          <a href="#M000386" class="method-signature">
          <span class="method-name">parse_options</span><span class="method-args">(args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Parse command-line options
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000386-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000386-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 97</span>
 97:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_options</span>(<span class="ruby-identifier">args</span>)
 98:       <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opt</span><span class="ruby-operator">|</span>
 99:         <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">&quot;USAGE: #{$0} [options] [session script path]&quot;</span>
100: 
101:         <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">'-n'</span>, <span class="ruby-value str">'--times [0000]'</span>, <span class="ruby-value str">'How many requests to process. Defaults to 100.'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:n</span>] = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_i</span> }
102:         <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">'-b'</span>, <span class="ruby-value str">'--benchmark'</span>, <span class="ruby-value str">'Benchmark instead of profiling'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:benchmark</span>] = <span class="ruby-identifier">v</span> }
103:         <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">'--open [CMD]'</span>, <span class="ruby-value str">'Command to open profile results. Defaults to &quot;open %s &amp;&quot;'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:open</span>] = <span class="ruby-identifier">v</span> }
104:         <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value str">'-h'</span>, <span class="ruby-value str">'--help'</span>, <span class="ruby-value str">'Show this help'</span>) { <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opt</span>; <span class="ruby-identifier">exit</span> }
105: 
106:         <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">parse</span> <span class="ruby-identifier">args</span>
107: 
108:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
109:           <span class="ruby-identifier">puts</span> <span class="ruby-identifier">opt</span>
110:           <span class="ruby-identifier">exit</span>
111:         <span class="ruby-keyword kw">end</span>
112:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:script</span>] = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">pop</span>
113:       <span class="ruby-keyword kw">end</span>
114:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000382" class="method-detail">
        <a name="M000382"></a>

        <div class="method-heading">
          <a href="#M000382" class="method-signature">
          <span class="method-name">profile</span><span class="method-args">(sandbox)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000382-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000382-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 72</span>
72:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">profile</span>(<span class="ruby-identifier">sandbox</span>)
73:       <span class="ruby-identifier">load_ruby_prof</span>
74: 
75:       <span class="ruby-identifier">results</span> = <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">profile</span> { <span class="ruby-identifier">benchmark</span>(<span class="ruby-identifier">sandbox</span>) }
76: 
77:       <span class="ruby-identifier">show_profile_results</span> <span class="ruby-identifier">results</span>
78:       <span class="ruby-identifier">results</span>
79:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000381" class="method-detail">
        <a name="M000381"></a>

        <div class="method-heading">
          <a href="#M000381" class="method-signature">
          <span class="method-name">run</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000381-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000381-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 60</span>
60:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>
61:       <span class="ruby-identifier">sandbox</span> = <span class="ruby-constant">Sandbox</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:script</span>])
62: 
63:       <span class="ruby-identifier">puts</span> <span class="ruby-value str">'Warming up once'</span>
64: 
65:       <span class="ruby-identifier">elapsed</span> = <span class="ruby-identifier">warmup</span>(<span class="ruby-identifier">sandbox</span>)
66:       <span class="ruby-identifier">puts</span> <span class="ruby-value str">'%.2f sec, %d requests, %d req/sec'</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">elapsed</span>, <span class="ruby-identifier">sandbox</span>.<span class="ruby-identifier">request_count</span>, <span class="ruby-identifier">sandbox</span>.<span class="ruby-identifier">request_count</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">elapsed</span>]
67:       <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\n#{options[:benchmark] ? 'Benchmarking' : 'Profiling'} #{options[:n]}x&quot;</span>
68: 
69:       <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:benchmark</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">benchmark</span>(<span class="ruby-identifier">sandbox</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">profile</span>(<span class="ruby-identifier">sandbox</span>)
70:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000384" class="method-detail">
        <a name="M000384"></a>

        <div class="method-heading">
          <a href="#M000384" class="method-signature">
          <span class="method-name">warmup</span><span class="method-args">(sandbox)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000384-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000384-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 88</span>
88:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">warmup</span>(<span class="ruby-identifier">sandbox</span>)
89:       <span class="ruby-constant">Benchmark</span>.<span class="ruby-identifier">realtime</span> { <span class="ruby-identifier">sandbox</span>.<span class="ruby-identifier">run</span> }
90:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000387" class="method-detail">
        <a name="M000387"></a>

        <div class="method-heading">
          <a href="#M000387" class="method-signature">
          <span class="method-name">load_ruby_prof</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000387-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000387-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 117</span>
117:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_ruby_prof</span>
118:         <span class="ruby-keyword kw">begin</span>
119:           <span class="ruby-identifier">require</span> <span class="ruby-value str">'ruby-prof'</span>
120:           <span class="ruby-comment cmt">#RubyProf.measure_mode = RubyProf::ALLOCATED_OBJECTS</span>
121:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
122:           <span class="ruby-identifier">abort</span> <span class="ruby-value str">'`gem install ruby-prof` to use the profiler'</span>
123:         <span class="ruby-keyword kw">end</span>
124:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000388" class="method-detail">
        <a name="M000388"></a>

        <div class="method-heading">
          <a href="#M000388" class="method-signature">
          <span class="method-name">show_profile_results</span><span class="method-args">(results)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000388-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000388-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/request_profiler.rb, line 126</span>
126:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">show_profile_results</span>(<span class="ruby-identifier">results</span>)
127:         <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span> <span class="ruby-node">&quot;#{RAILS_ROOT}/tmp/profile-graph.html&quot;</span>, <span class="ruby-value str">'w'</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
128:           <span class="ruby-constant">RubyProf</span><span class="ruby-operator">::</span><span class="ruby-constant">GraphHtmlPrinter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">results</span>).<span class="ruby-identifier">print</span>(<span class="ruby-identifier">file</span>)
129:           <span class="ruby-node">`#{options[:open] % file.path}`</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:open</span>]
130:         <span class="ruby-keyword kw">end</span>
131: 
132:         <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span> <span class="ruby-node">&quot;#{RAILS_ROOT}/tmp/profile-flat.txt&quot;</span>, <span class="ruby-value str">'w'</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
133:           <span class="ruby-constant">RubyProf</span><span class="ruby-operator">::</span><span class="ruby-constant">FlatPrinter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">results</span>).<span class="ruby-identifier">print</span>(<span class="ruby-identifier">file</span>)
134:           <span class="ruby-node">`#{options[:open] % file.path}`</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:open</span>]
135:         <span class="ruby-keyword kw">end</span>
136:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>